package com.woniuxy.educationplatform.controller;

import com.woniuxy.educationplatform.bean.CourseBean;
import com.woniuxy.educationplatform.service.ICourseService;
import com.woniuxy.educationplatform.service.IProjectService;
import com.woniuxy.educationplatform.service.ISubjectService;
import com.woniuxy.educationplatform.service.ITeacherService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/course")

public class CourseController {

    @Resource
    private IProjectService projectServiceImpl;
    @Resource
    private ISubjectService subjectServiceImpl;
    @Resource
    private ITeacherService teacherServiceImpl;
    @Resource
    private ICourseService courseServiceImpl;

    @RequestMapping("/findAll")
    public List<CourseBean> findAll(){
        System.out.println("开始查询所有的课程");
        List<CourseBean> list=courseServiceImpl.findAll();
        System.out.println("查询完毕");
        return list;
    }

    @RequestMapping("/more")
    public void saveCourseBean(String courseName,Long pid,Long sid){
        System.out.println("开始存储课程");
        System.out.println(pid);
        System.out.println(sid);
        System.out.println(courseName);
        CourseBean courseBean=new CourseBean();
        courseBean.setCourseName(courseName);
        courseBean.setSubjectBean(subjectServiceImpl.findById(sid));
        courseServiceImpl.saveCourseBean(courseBean);
        System.out.println(courseBean);
        System.out.println("完成新建了");
    }

    @RequestMapping("/findOneByCondition")
    public List<CourseBean> findOneByCondition(String courseName,Long id){
        System.out.println("开识根据条件查询课程");
        System.out.println(courseName);
        System.out.println(id);
        List<CourseBean> list=courseServiceImpl.findOneByCondition(courseName, id);
        System.out.println("查询完毕");
        return list;
    }

    @RequestMapping("/del")
    public void del(Long id){
        System.out.println("开始删除程序");
        System.out.println(id);
        courseServiceImpl.delete(id);
        System.out.println("删除完成");
    }

    @RequestMapping("/change")
    public void update(String courseName,Long id){
        System.out.println("开始修改");
        System.out.println(courseName);
        System.out.println(id);
        CourseBean courseBean=new CourseBean();
        courseBean.setCourseName(courseName);
        courseBean.setId(id);
        courseServiceImpl.updateCourseBean(courseBean);
        System.out.println(courseBean);
        System.out.println("修改完成");
    }
    @RequestMapping("/getcourse")
    public String[] getcourse(){
    return courseServiceImpl.getCourseName();
    }
}
